<!DOCTYPE HTML>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>火车票</title>
		<script src="/js/jquery.js"></script>
		<style>
			body, div, input, select, button {
				margin: 0;
				font-size: 12px;
				font-family: Arial, '宋体';
			}
			#divRules {
				width: 750px;
				margin-left: auto;
				margin-right: auto;
			}
			ul {
				padding: 0px;
			}
			li {
				float: left;
				width: 100%;
				padding-top: 5px;
				padding-bottom: 4px;
				list-style-type: none;
				border-top: 1px solid #CCC;
			}
			li .title {
				float: left;
				width: 14%;
				line-height: 28px;
				font-weight: bold;
			}
			li .dater {
				float: left;
				width: 10%;
				line-height: 28px;
				font-weight: bold;
			}
			li .submit {
				float: left;
				width: 76%;
				text-align: right;
				line-height: 28px;
			}
			li .passenger {
				float: left;
				width: 34%;
				padding-left: 4%;
				color: #999;
				line-height: 20px;
			}
			li .times {
				float: left;
				width: 10%;
				color: #999;
				line-height: 20px;
			}
			li .no {
				float: left;
				width: 52%;
				text-align: right;
				color: #999;
				line-height: 20px;
			}
		</style>
	</head>
	<body>
		<div id="divRules">
			<ul>
				<?php
				$fromId = 0;
				
				foreach ($rules as $from => $froms) {
					foreach ($froms as $to => $tos) {
						foreach ($tos as $dater => $rule) {
							echo '<li>';
							echo '<form name="form' . ++$fromId . '" action="/panel" target="_blank">';
							echo "<input type='hidden' name='from' value='{$from}' />";
							echo "<input type='hidden' name='to' value='{$to}' />";
							echo "<input type='hidden' name='dater' value='{$dater}' />";
							echo "<input type='hidden' name='sid' />";
							echo "<input type='hidden' name='user' />";
							echo "<div class='title'>$from ~ $to</div>";
							echo "<div class='dater'>$dater</div>";
							
							echo '<div class="submit">';
							foreach ($users as $username => $item) {
								$x = strtoupper(uniqid());
								echo "&nbsp;<input type='button' value='{$item[0]}' onclick='onSubmits($fromId, \"$x\", \"$username\");' />";
							}
							echo '</div>';
							
							foreach ($rule as $rid => $r) {
								$passenger = [];
								foreach ($r['passenger'] as $x) {
									$passenger[] = $x[0];
								}
								
								$seat = [];
								foreach ($r['seat'] as $x) {
									$seat[] = ($x[0] == 'X' ? '所有' : $x[0]) . '：' . $x[1];
								}
								
								echo '<div class="passenger">' . implode('、', $passenger) . '</div>';
								echo '<div class="times">' . date('H:i', $r['early']) . '-' . date('H:i', $r['latest']) . '</div>';
								echo '<div class="no">' . implode('、', $seat) . '</div>';
							}
							
							echo '</form>';
							echo '</li>';
							echo '<span style="clear: left;"></span>';
						}
					}
				}
				?>
				<li>&nbsp;</li>
			</ul>
		</div>
		<script>
			function onSubmits(fid, sid, user) {
				var x = document.forms["form" + fid];

				x.elements['sid'].value = sid;
				x.elements['user'].value = user;

				x.submit();
			}
		</script>
	</body>
</html>